﻿//Change user language
$(document).ready(function() {
$("#language").change(function() {
        var form = $(this).parents('form');
        form.submit();
    });
});

//Change markup mode to view or design
$(document).ready(function() {
    $(".markupMode").change(function() {
        var form = $(this).parents('form');
        form.submit();
    });
});

//Menu
$(document).ready(function() {
    $(".menu-item li").mouseover(function() {
        $(this).find(".sub-menu").css("display", "block");
        $(this).find(".sub-menu .menu-item-title").css("background-position", "0 -28px");
        $(this).find(".sub-menu .menu-item-title span").css("background-position", "100% -28px");
    });

    $(".menu-item li").mouseout(function() {
        $(this).find(".sub-menu").css("display", "none");
        $(this).find(".sub-menu .menu-item-title").css("background-position", "0 0px");
        $(this).find(".sub-menu .menu-item-title span").css("background-position", "100% 5px");
    });
});

//Collapsable panel
$(document).ready(function() {
    $(".collapsablePanelImageContainer").click(function() {
        var item = $(this).parent().find(".collapsablePanelContent");
        if (item.css("display") == 'none') {
            $(this).parent().find(".collapsablePanelContent").slideDown(100);
            $(this).children().removeClass("collapsablePanelCollapsedImage");
            $(this).children().addClass("collapsablePanelExpandedImage");
        }
        else {
            $(this).parent().find(".collapsablePanelContent").slideUp(100);
            $(this).children().removeClass("collapsablePanelExpandedImage");
            $(this).children().addClass("collapsablePanelCollapsedImage");
        }
    });
});

//Module context menu actions
$(document).ready(function() {
    $(".pageActions").mouseover(function() {
        $(this).find(".sub-menu").css("display", "block");
    });
    $(".pageActions").mouseout(function() {
        $(this).find(".sub-menu").css("display", "none");
    });
});


//Submits form
function submitForm(item, action) {
    var form = document.getElementById(item);
    form.action = action;
    form.submit();
    return true;
}


var flashit = function ($this, duration, cycles) {
    if (cycles < 1) return;
    $this.fadeTo(duration / 2, 0.2, function () {
        $this.fadeTo(duration / 2, 1, function () {
            flashit($this, duration, cycles - 1);
        });
    });
};

var scrollIntoView = function ($this, $parent) {
    var divOffset = $parent.offset().top;
    var pOffset = $this.offset().top;
    var pScroll = pOffset - divOffset;
    $parent.scrollTop(pScroll);
};

